# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-maxmind-db
pkgver=1.1.1
_testdatacommit=507c17e7cf266bb47bca4922aa62071cb21f6d06
pkgrel=1
pkgdesc='Generic connection pool for Ruby'
arch=(any)
url='https://github.com/maxmind/MaxMind-DB-Reader-ruby'
license=(Apache MIT)
depends=(ruby)
makedepends=(ruby-minitest ruby-rake)
options=(!emptydirs)
source=(https://github.com/maxmind/MaxMind-DB-Reader-ruby/archive/v$pkgver/$pkgname-$pkgver.tar.gz
        maxmind-db-$_testdatacommit.tar.gz::https://github.com/maxmind/MaxMind-DB/archive/$_testdatacommit.tar.gz)
sha256sums=('bbf3877a36105f797f01ae2fca0e0a4babc39035358b0f2fb1bbe1b7ae05f1b1'
            '5e1e04e0e97a9af7ffef42271dd15d8674a99a2a9f23817414f7fe795e81e520')

prepare() {
  cd MaxMind-DB-Reader-ruby-$pkgver
  sed '/[rR]ubo[cC]op/d' -i maxmind-db.gemspec Rakefile
  rmdir test/data
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd MaxMind-DB-Reader-ruby-$pkgver
  gem build maxmind-db.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    maxmind-db-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd MaxMind-DB-Reader-ruby-$pkgver
  ln -s "$srcdir"/MaxMind-DB-$_testdatacommit test/data
  GEM_HOME="tmp_install/$_gemdir" rake
  rm test/data
}

package() {
  cd MaxMind-DB-Reader-ruby-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE-MIT -t "$pkgdir"/usr/share/licenses/$pkgname/
}
